var evalNumberId = getParameter("evalNumberId");
var uid = getParameter("uid");
var maxd = 0;
$(function() {
	rt();
	
});

function rt(){
	var urlStr = serverPath + "/app/doctor/doctor/assess.do";
	var jsonStr = '{method:"cHDReport",requestlist:[{evalNumberId:"'+evalNumberId+'"}],  version:"1.0",uid:"'+uid+'", requestsource:"doctor"}' ;
	UseAjax(urlStr, jsonStr, document.cookie, xinxueguan, '1');
	}

function xinxueguan(nodeArrays) {
	var nodeArray=nodeArrays.resultlist[0];
	if (nodeArray && nodeArray.hypertensionreport && nodeArray.knowledgebaseresult) {
		
		$("#futureRisk").show();
		
		var wi = nodeArray.hypertensionreport;
		var kb = nodeArray.knowledgebaseresult;
		var attack = wi.attack + "%";
		var standardattack = wi.standardattack + "%";

		var diease = "";
		if (wi.chd > 0) {
			diease = "冠心病";
		}
		if (wi.stroke > 0) {
			diease = "脑卒中";
		}
		if (wi.chd > 0 && wi.stroke > 0) {
			diease = "冠心病、脑卒中";
		}

		if (wi.ishaddisease > 0) {
			$('#chart_title').html('您已患缺血性心血管疾病');
			$('#chart_content').hide();
			
			var text = '';

			text = text + '<h2>危险因素列表:</h2>';
		    text = text + '<table class="risk-list">';
		    text = text + '<tr><th class="th1">危险因素</th><th class="th2">您的情况</td><th class="th3 ">参考值</th></tr>';
		    text = text + '<tr><td>年龄</td><td>' + wi.age + '</td><td>随年龄增长风险增高</td></tr>';
		    if (wi.fdisease > 0) {
		    	text = text + '<tr class="high-light"><td>家族史</td><td>有</td><td>无</td></tr>';
		    } else {
		    	text = text + '<tr><td>家族史</td><td>无</td><td>无</td></tr>';
		    }
		    if (wi.dm > 0) {
		    	text = text + '<tr class="high-light"><td>糖尿病</td><td>有</td><td>无</td></tr>';
		    } else {
				text = text + '<tr><td>糖尿病</td><td>无</td><td>无</td></tr>';
		    }
			if (parseFloat(wi.bmi) < 18.5 || parseFloat(wi.bmi) >= 24) {
				text = text + '<tr class="high-light"><td>BMI</td><td>' + wi.bmi + '</td><td>18.5&le;BMI&lt;24</td></tr>';
			} else {
				text = text + '<tr><td>BMI</td><td>' + wi.bmi + '</td></td><td>18.5&le;BMI&lt;24</td></tr>';
			}
			if (parseFloat(wi.systolic) >= 120) {
				text = text + '<tr class="high-light"><td>血压（收缩压）</td><td>' + wi.systolic + '</td><td><120mmHg</td></tr>';
			} else {
				text = text + '<tr><td>血压（收缩压）</td><td>' + wi.systolic + '</td><td><120mmHg</td></tr>';
			}
			if (parseFloat(wi.diastolic) >= 80) {
				text = text + '<tr class="high-light"><td>血压（舒张压）</td><td>' + wi.diastolic + '</td><td><80mmHg</td></tr>';
			} else {
				text = text + '<tr><td>血压（舒张压）</td><td>' + wi.diastolic + '</td><td><80mmHg</td></tr>';
			}
			if (wi.smoke == 0) {
				text = text + '<tr class="high-light"><td>吸烟情况</td><td>吸烟</td><td>不吸烟</td></tr>';
			} else {
				text = text + '<tr><td>吸烟情况</td><td>不吸烟</td><td>不吸烟</td></tr>';
			}
			if (parseFloat(wi.tc) >= 5.18) {
				text = text + '<tr class="high-light"><td>总胆固醇</td><td>' + wi.tc + '</td><td><5.18mmol/l</td></tr>';
			} else {
				text = text + '<tr><td>总胆固醇</td><td>' + wi.tc + '</td><td><5.18mmol/l</td></tr>';
			}
			text = text + '</table>';

			text = text + '<h2>风险提示：</h2>';
			text = text + '<ul>';
			text = text + '<li>' + kb.knowledgeBase1 + diease + '；</li>';
			text = text + '<li>' + kb.knowledgeBase2 + '</li>';
			text = text + '<li>' + kb.knowledgeBase3 + wi.risks + '；</li>';
			text = text + '<li>' + kb.knowledgeBase4 + '</li>';
			text = text + '</ul>';

			$('#reportContent').html(text);
		} else {
			$('#chart_title').html('您未来10年缺血性心血管疾病的发病风险为：<font color="red">' + attack + '</font>');			
			d1 = wi.attack;
			d2 = wi.standardattack;
			if(d1>d2){
				maxd=d1;
			} else {
				maxd=d2;
			}
			var colors = Highcharts.getOptions().colors,
			categories = [ '您的当前风险', '您的理想风险' ], name = '未来十年缺血性心血管疾病风险评估',
			
			data = [
					{
						y : d1,
						color : "#fb0800",
						drilldown : {
							name : 'MSIE versions',
							categories : [ 'MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0',
									'MSIE 9.0' ],
							data : [ 10.85, 7.35, 33.06, 2.81 ],
							color : colors[0]

						}
					},
					{
						y : d2,
						color : " #42b1cf",
						drilldown : {
							name : 'Firefox versions',
							categories : [ 'Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5',
									'Firefox 3.6', 'Firefox 4.0' ],
							data : [ 0.20, 0.83, 1.58, 13.12, 5.43 ],
							color : colors[1]
						}
					} ];

			function setChart(name, categories, data, color) {
				chart.xAxis[0].setCategories(categories, false);
				chart.series[0].remove(false);
				chart.addSeries({
					name : name,
					data : data,
					title : title,
					color : color || 'white'
				}, false);
				chart.redraw();
			}

			var chart = $('#container')
					.highcharts(
							{
								chart : {
									type : 'column'
								},
								title : {
									text : '未来十年缺血性心血管疾病风险评估',

									style : {
										fontWeight : 'bold',
										color : 'red',
										fontSize : '18px'
									}
								},

								xAxis : {
									categories : categories,
									style : {
										color : 'red'
									}
								},

								yAxis : {
									title : {
										text : '风险值',
										style : {
											color : '#000000',
											fontWeight : 'bold'
										}
									},
									max :maxd*1.2,
									min : 0,
									tickPixelInterval : 40,
									//gridLineColor : 'red',
									tickmarkPlacement : 'between',
									tickColor : '#c0d0e0',
									tickWidth : 0,
									plotlines : 'dashed',
									gridLineWidth : 1,

								},
								plotOptions : {
									column : {
										cursor : 'pointer',
										dataLabels : {
											enabled : true,
											color : colors[0],
											style : {
												fontWeight : 'bold'
											},
											formatter : function() {
											//	return "a";
											}
										}
									}
								},

								series : [ {
									 events: {
			                                //控制图标的图例legend不允许切换
			                               legendItemClick: function (event){                                    
			                                return false; //return  true 则表示允许切换
			                                }
			                            },
									name : name,
									data : data,
									color : 'red'
								} ],
								exporting : {
									enabled : true
								},

							}).highcharts(); 
			var text = '';

			text = text + '<h2>危险因素列表:</h2>';
		    text = text + '<table class="risk-list">';
		    text = text + '<tr><th class="th1">危险因素</th><th class="th2">您的情况</td><th class="th3 ">参考值</th></tr>';
		    text = text + '<tr><td>年龄</td><td>' + wi.age + '</td><td>随年龄增长风险增高</td></tr>';
		    if (wi.fdisease > 0) {
		    	text = text + '<tr class="high-light"><td>家族史</td><td>有</td><td>无</td></tr>';
		    } else {
		    	text = text + '<tr><td>家族史</td><td>无</td><td>无</td></tr>';
		    }
		    if (wi.dm > 0) {
		    	text = text + '<tr class="high-light"><td>糖尿病</td><td>有</td><td>无</td></tr>';
		    } else {
				text = text + '<tr><td>糖尿病</td><td>无</td><td>无</td></tr>';
		    }
			if (parseFloat(wi.bmi) < 18.5 || parseFloat(wi.bmi) >= 24) {
				text = text + '<tr class="high-light"><td>BMI</td><td>' + wi.bmi + '</td><td>18.5&le;BMI&lt;24</td></tr>';
			} else {
				text = text + '<tr><td>BMI</td><td>' + wi.bmi + '</td></td><td>18.5&le;BMI&lt;24</td></tr>';
			}
			if (parseFloat(wi.systolic) >= 120) {
				text = text + '<tr class="high-light"><td>血压（收缩压）</td><td>' + wi.systolic + '</td><td><120mmHg</td></tr>';
			} else {
				text = text + '<tr><td>血压（收缩压）</td><td>' + wi.systolic + '</td><td><120mmHg</td></tr>';
			}
			if (parseFloat(wi.diastolic) >= 80) {
				text = text + '<tr class="high-light"><td>血压（舒张压）</td><td>' + wi.diastolic + '</td><td><80mmHg</td></tr>';
			} else {
				text = text + '<tr><td>血压（舒张压）</td><td>' + wi.diastolic + '</td><td><80mmHg</td></tr>';
			}
			if (wi.smoke == 0) {
				text = text + '<tr class="high-light"><td>吸烟情况</td><td>吸烟</td><td>不吸烟</td></tr>';
			} else {
				text = text + '<tr><td>吸烟情况</td><td>不吸烟</td><td>不吸烟</td></tr>';
			}
			if (parseFloat(wi.tc) >= 5.18) {
				text = text + '<tr class="high-light"><td>总胆固醇</td><td>' + wi.tc + '</td><td><5.18mmol/l</td></tr>';
			} else {
				text = text + '<tr><td>总胆固醇</td><td>' + wi.tc + '</td><td><5.18mmol/l</td></tr>';
			}
			text = text + '</table>';

			text = text + '<h2>风险提示：</h2>';
			text = text + '<ul>';
			text = text + '<li>' + kb.knowledgeBase1 + attack + '；</li>';
			text = text + '<li>' + kb.knowledgeBase2 + standardattack + '；</li>';
			text = text + '<li>' + kb.knowledgeBase3 + wi.risks + '；</li>';
			text = text + '<li>' + kb.knowledgeBase4 + '</li>';
			text = text + '</ul>';

			$('#reportContent').html(text);
		}
	} else {
		$('#chart_title').hide();
		$('#chart_content').hide();
		$('#reportContent').html(
			'<div><span style="font-size:16px;"><span style="color: rgb(105, 105, 105); "><span style="font-family: 黑体; ">没有记录</span></span></span></div>'
		);
	}
	
}
// 获取url参数
function getParameter(param) {
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
		return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	return query.substring(iStart, iEnd);
}